package com.xo.common.validator;

import com.xo.common.validator.log.Phone;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;

public class PhoneValidator implements ConstraintValidator<Phone, String> {

    private String regex;


    @Override
    public void initialize(Phone constraintAnnotation) {
         this.regex = constraintAnnotation.regex();
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(s)) {
            return true;
        }
        return s.matches(regex);
    }
}
